package ducna.android.aoeclip.common.controller;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;

import ducna.android.aoeclip.R;
import ducna.android.aoeclip.common.utils.Logger;

/**
 * Created by DUCNA on 11/4/2014.
 */
public abstract class BaseActivity extends ActionBarActivity {
    public static final String TAG = BaseActivity.class.getSimpleName();

    private ProgressDialog mProgressDialog;
    private Toolbar mToolbar;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getResID());
        mToolbar = (Toolbar) findViewById(R.id.toolbar);
        mToolbar.setTitleTextColor(getResources().getColor(R.color.white));
        if (mToolbar != null){
            setSupportActionBar(mToolbar);
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        }
    }

    protected abstract int getResID();
    // action bar
    protected void setActionBarIcon(int iconRes){
        mToolbar.setNavigationIcon(iconRes);
    }

    protected void setNavigationClick(View.OnClickListener listener){
        mToolbar.setNavigationOnClickListener(listener);
    }

    protected void setActionBarTitle(String title){
        mToolbar.setTitle(title);
    }
    // show dialog
    protected void initProgressDialog(){
        mProgressDialog = new ProgressDialog(this);
        mProgressDialog.setTitle(R.string.app_name);
        mProgressDialog.setMessage(getResources().getString(R.string.please_wait));
        mProgressDialog.setCancelable(false);
        mProgressDialog.setIndeterminate(true);
        mProgressDialog.show();
    }

    // dismiss dialog
    protected void hideProgressDialog(){
        if (mProgressDialog != null){
            mProgressDialog.dismiss();
            mProgressDialog = null;
        }
    }

    protected void showProgressDialog(){
        if (mProgressDialog != null)
            mProgressDialog.show();
    }
}
